package simple.common;

import java.util.Date;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;

public abstract class BaseLogic<T extends BaseEntity> {

    @Inject
    protected Dao dao;

    public T insert(T entity) {
        Date now = new Date();
        entity.setCreateAt(now);
        entity.setModifyAt(now);
        dao.insert(entity);
        return entity;
    }

    public T update(T entity) {
        Date now = new Date();
        entity.setModifyAt(now);
        dao.update(entity);
        return entity;
    }

    public void delete(T entity) {
        dao.delete(entity);
    }
}
